package org.lab.data;


public class QuoteUtil {
	
	private Ticker ticker;
	
	QuoteUtil(Ticker ticker) {
		this.ticker = ticker;
	}

	public float CloseToLastClosePercent(Quote quote) {
		if (ticker.getQuotes().indexOf(quote) > -1) {
			System.out.println("Index: "+ticker.getQuotes().indexOf(quote)+" - "+(ticker.getQuotes().indexOf(quote)+1));
			Quote quoteBefore = ticker.getQuotes().get(ticker.getQuotes().indexOf(quote)+1);
			return (quote.getClose()-quoteBefore.getClose())/quoteBefore.getClose()*100;
		} else if (ticker.getQuotes().indexOf(quote) == 0) {
			return OpenToClosePercent(quote);
		}
		return 0;
	}
	
	public float OpenToClosePercent(Quote quote) {
		return (quote.getClose()-quote.getOpen())/quote.getOpen()*100;
	}
	
	public float GapFromLastClosePercent(Quote quote) {
		Quote quoteBefore = ticker.getQuotes().get(ticker.getQuotes().indexOf(quote)-1);
		return (quote.getOpen()-quoteBefore.getClose())/quoteBefore.getClose()*100;
	}
	
	public Quote getQuoteBefore(Quote quote) {
		if (ticker.getQuotes().indexOf(quote) != ticker.getQuotes().size()-1) {
			return ticker.getQuotes().get(ticker.getQuotes().indexOf(quote)+1);
		} else {
			return null;
		}
	}
	
	public Quote getQuoteBefore(Quote quote, int num) {
		if (ticker.getQuotes().indexOf(quote) != ticker.getQuotes().size()-num) {
			return ticker.getQuotes().get(ticker.getQuotes().indexOf(quote)+num);
		} else {
			return null;
		}
	}
	
	public Quote getQuoteAfter(Quote quote) {
		if (ticker.getQuotes().indexOf(quote) != 0) {
			return ticker.getQuotes().get(ticker.getQuotes().indexOf(quote)-1);
		} else {
			return null;
		}
	}
	
	public Quote getQuoteAfter(Quote quote, int num) {
		if (ticker.getQuotes().indexOf(quote) != num-1) {
			return ticker.getQuotes().get(ticker.getQuotes().indexOf(quote)-num);
		} else {
			return null;
		}
	}
	
	public Quote getFirstQuote() {
		return ticker.getQuotes().get(0);
	}

	public Quote getLastQuote() {
		return ticker.getQuotes().get(ticker.getQuotes().size()-1);
	}

}